using UnityEngine;

public class LevelFinishActivatorPart : MonoBehaviour
{
	public Material materialActivated;

	public Material materialDeactivated;

	private Quaternion initRotation;

	private bool init = true;

	private bool activated;

	private float speed = 180f;

	private bool dormant = true;

	private void Update()
	{
		if (init || dormant)
		{
			return;
		}
		float maxDegreesDelta = Time.deltaTime * speed;
		if (activated)
		{
			if (base.transform.rotation != initRotation * Quaternion.Euler(15f, 0f, 0f))
			{
				base.transform.rotation = Quaternion.RotateTowards(base.transform.rotation, initRotation * Quaternion.Euler(15f, 0f, 0f), maxDegreesDelta);
				return;
			}
			base.GetComponent<Renderer>().material = materialActivated;
			dormant = true;
		}
		else if (base.transform.rotation != initRotation)
		{
			base.transform.rotation = Quaternion.RotateTowards(base.transform.rotation, initRotation, maxDegreesDelta);
		}
		else
		{
			base.GetComponent<Renderer>().material = materialDeactivated;
			dormant = true;
		}
	}

	private void DoInit()
	{
		if (init)
		{
			initRotation = base.transform.rotation;
			init = false;
		}
	}

	public void ActivatePartDelayed(float delay)
	{
		Invoke("ActivatePart", delay);
	}

	public void ActivatePart()
	{
		DoInit();
		activated = true;
		dormant = false;
	}

	public void DeactivatePart()
	{
		DoInit();
		activated = false;
		dormant = false;
	}
}
